<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>采购订单编辑</title>
	<!-- import css and js --> 
	<%@ include file="/common/metaInput.jsp" %>  
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
var basic_Url="${ctx}/yd/logic/po";
var grid;
$(function(){
	
	 $("#spcode").change(function(){
		 	grid.loadData();
			$("#spname").val("");
			$("#spattachperson").val("");
			$("#sptelephone").val("");
			$("#spmobil").val("");
			$("#spfax").val("");
			$("#spaddress").val("");
			if(''!= $(this).val()){
				$.ajax({
	    		      url: basic_Url+"/getGysInfo.do",
	    		      global: false,
	    		      type: "POST",
	    		      dataType: "json",
	    		      data: ({
	    		    	  gysCode : $(this).val()
	    		      }),		     
	    		      success: function(msg){
	    		    	if(undefined != msg && undefined != msg.gys && null != msg.gys){
	    		    		$("#spname").val(msg.gys.name);
	    		    		$("#spattachperson").val(msg.gys.attachperson);
	    					$("#sptelephone").val(msg.gys.telephone);
	    					$("#spmobil").val(msg.gys.mobil);
	    					$("#spfax").val(msg.gys.fax);
	    					$("#spaddress").val(msg.gys.address);
	    					$("#spemail").val(msg.gys.email);
	    		    	}else{
	    		    		alert("返回对象为空");
	    		    	}
	    	   			
	    		      }
	    	   });
			}
		}); 
	 
	 $("#currency").change(function(){ 
		 <c:forEach items='${currency}' var='item'>
		 if('${item.currencyname}'==$("#currency").val()){
				$("#exchangeRate").val('${item.exchangeRate}');
			}
		</c:forEach>
		grid.reRender();	
		}); 
	 
// 	 $("#kdgs").change(function(){ 
// 			$("#creategsname").val($("#kdgs").find("option:selected").text());
// 			$("#creategscode").val($("#kdgs").val());
// 		}); 
var column1 =  [
      				  { display: 'id', name: 'id', width: 1,hide:1 },
    				  { display: 'materialsid', name: 'materialsid', width: 1,hide:1 },
    				  { display: '<font color="gray">物料编码</font>', name: 'code', width: 100 },
                      { display: '<font color="gray">物料名称</font>', name: 'name', width: 150 },
                      { display: '<font color="gray">物料类型</font>', name: 'itmetype', width: 150 },
                      { display: '描述<font color="red">*</font>', name: 'spec', width: 245,editor: { type: 'text'}},
                      { display: '<font color="gray">物料是否可用批次</font>', name: 'openBatch' ,hide:true,width: 150, render: function (item, rowindex, value, column)
						    {
		            	   	if(item.openBatch=="Y"){
		            	   		return "可用";
		            	   	}else{
		            	   		return "不可用";
		            	   	}
					   		
				    }},
                      { display: '单位<font color="red">*</font>', name: 'unit', width: 120,editor : {
                  	 	   type:'selecturl',dataItem:'dataItem',path:'${ctx}/yd/basic/measurementUnit/unitlist.do',valueColumnName: 'unitname', displayColumnName: 'unitname'}, render: function (item)
                             {
                  	 		  var dataitem = $.parseJSON($("#dataItem").val());
                  	 		  if(dataitem!=null){
                  	 			 for (var i = 0; i < dataitem.length; i++)
                                   {
                                       if (dataitem[i]['unitname'] == item.unit&&dataitem[i]['materialscode']==item.code){
                                     	  	 grid.updateCell('unitconvert', dataitem[i]['unitconvert'], item);
                                     	  	 return dataitem[i]['unitname'];
                                          
                                       } 
                                   }
                  	 		  }
                  	 		 
                                 return item.unit;
                             }},
                         { display: '数量<font color="red">*</font>', name: 'quantity', width: 120,editor: { type: 'float'},render:function(item){
//                        	  if(item.unit != null && ''!=item.unit){
//    	                    	  if(item.unitconvert==null||item.unitconvert==''){
//    		              				$.ajax({
//    		              				      url: "${ctx}/yd/basic/measurementUnit/getUnitconvert.do",
//    		              				      global: false,
//    		              				      type: "POST",
//    		              				      async:false,
//    		              				      dataType: "json",
//    		              				      data: ({
//    		              				    	   id:item.materialsid,
//    		              				    	   code:item.code,
//    		              				    	   unit:item.unit,
//    		              				      }),		     
//    		              				      success: function(msg){
//    		              				    	 result = msg;
//    		              				    	 var bmu = eval("("+JSON.stringify(result)+")"); 
//    		              				    	grid.updateCell('unitconvert', bmu[0].unitconvert, item);
//    		              				      }
//    		              			   });
//    	              		      }
//                        	  }
                       	  if((item.quantity!=null&& !isNaN(item.quantity)) && (item.unitconvert != null && !isNaN(item.unitconvert))){
                       	  		grid.updateCell('jquantity', (item.unitconvert*item.quantity), item);
                       	  	 }
                          	  return (item.quantity==undefined ? 0:(1*item.quantity).toFixed(4));
                         }},
                      { display: '<font color="gray">基本单位</font>', name: 'junit', width: 120},
                      { display: '<font color="gray">基本单位数量', name: 'jquantity', width: 120},
                      { display: '含税单价<font color="red">*</font>', name: 'stockPrice', width: 120,editor: { type: 'float'},render:function(item){
                    	  if(($("#exchangeRate").val() != "" && $("#exchangeRate").val()!=null && $("#exchangeRate").val() != undefined) && (!isNaN(item.stockPrice) && item.stockPrice!=null && item.stockPrice != undefined)){
                    		  item.rmb=item.stockPrice*parseFloat($("#exchangeRate").val()).toFixed(4);
                        	  }
                    	  return (1*item.stockPrice).toFixed(4);
 	                  }},
 	                 { display: '<font color="gray">人民币含税单价</font>', name: 'rmb', width: 120,render:function(item){
                   	  if(($("#exchangeRate").val() != "" && $("#exchangeRate").val()!=null && $("#exchangeRate").val() != undefined) && (!isNaN(item.rmb) && item.rmb!=null && item.rmb != undefined)){
                		  item.stockPrice=item.rmb/parseFloat($("#exchangeRate").val()).toFixed(4);
                    	  }
                    	  return (1*item.rmb).toFixed(4);
 	                  }},
                     { display: '税率(%)<font color="red">*</font>', name: 'taxRate', width: 120,editor: { type: 'float'},render:function(item){
                    	  if((item.stockPrice!=null&&item.stockPrice!=NaN)&&(item.taxRate != null && item.taxRate !=NaN)){
                    		 // alert("item:"+item.toSource());
                    		  grid.updateCell('taxrateMoney',(item.stockPrice*(item.taxRate/100)).toFixed(4), item);
                    		  grid.updateCell('price', (item.stockPrice-(parseFloat(item.stockPrice)*(item.taxRate/100))).toFixed(4), item); 
                    	  }
                       	  return (item.taxRate==undefined ? 0:(1*item.taxRate).toFixed(4));
                      }},
                      { display: '<font color="gray">税额</font>', name: 'taxrateMoney', width: 120},
                      { display: '<font color="gray">不含税单价</font>', name: 'price', width: 120},
                      { display: '折扣(%)<font color="red">*</font>', name: 'discount', width: 120,editor: { type: 'float'},render:function(item){
                    	  if((item.stockPrice!=null&&item.stockPrice!=NaN)&&(item.discount != null && item.discount !=NaN)){
                    		  grid.updateCell('discountMoney',(item.price*(item.discount/100)).toFixed(4), item);
                    		  grid.updateCell('hsdiscountMoney',(item.stockPrice*(item.discount/100)).toFixed(4), item);
                    		  if(item.jquantity!=null&&item.jquantity!=NaN){
                    		  grid.updateCell('summoney', (parseFloat(item.discountMoney)*parseFloat(item.jquantity)).toFixed(4), item);
                    		  grid.updateCell('sumPMoney', (parseFloat(item.hsdiscountMoney)*item.jquantity).toFixed(4), item);
                    	  } }
                       	  return (item.discount==undefined ? 100:(1*item.discount).toFixed(4));
                      }},
                      { display: '<font color="gray">不含税折扣额</font>', name: 'discountMoney', width: 120,},
                      { display: '<font color="gray">含税折扣额</font>', name: 'hsdiscountMoney', width: 120},
                      { display: '<font color="gray">不含税总金额</font>', name: 'summoney', width: 120},
                      { display: '<font color="gray">含税总金额</font>', name: 'sumPMoney', width: 120},
                      { display: '<font color="gray">单位换算率</font>', name: 'unitconvert', width:100 }];
                	 	
var column2 = [
      				  { display: 'id', name: 'id', width: 1,hide:1 },
    				  { display: 'materialsid', name: 'materialsid', width: 1,hide:1 },
    				  { display: '<font color="gray">物料编码</font>', name: 'code', width: 100 },
                      { display: '<font color="gray">物料名称</font>', name: 'name', width: 150 },
                      { display: '<font color="gray">物料类型</font>', name: 'itmetype', width: 150 },
                      { display: '描述<font color="red">*</font>', name: 'spec', width: 245 },
                      { display: '<font color="gray">物料是否可用批次</font>', name: 'openBatch' ,width: 150, hide:true,render: function (item, rowindex, value, column)
						    {
		            	   	if(item.openBatch=="Y"){
		            	   		return "可用";
		            	   	}else{
		            	   		return "不可用";
		            	   	}
					   		
				    }},
                      { display: '单位<font color="red">*</font>', name: 'unit', width: 120},
                      { display: '数量<font color="red">*</font>', name: 'quantity', width: 120},
                      { display: '<font color="gray">基本单位</font>', name: 'junit', width: 120},
                      { display: '<font color="gray">基本单位数量</font>', name: 'jquantity', width: 120},
                      { display: '含税单价<font color="red">*</font>', name: 'stockPrice', width: 120,render:function(item){
                    	  return (1*item.stockPrice).toFixed(4);
                      }},
                      { display: '<font color="gray">人民币含税单价</font>', name: 'rmb', width: 120,render:function(item){
                       	  if(($("#exchangeRate").val() != "" && $("#exchangeRate").val()!=null && $("#exchangeRate").val() != undefined) && (!isNaN(item.stockPrice) && item.stockPrice!=null && item.stockPrice != undefined)){
                    		  item.rmb=item.stockPrice*parseFloat($("#exchangeRate").val()).toFixed(4);
                        	  }
                        	  return (1*item.rmb).toFixed(4);
     	                  }},
                      { display: '税率(%)<font color="red">*</font>', name: 'taxRate', width: 120},
                      { display: '<font color="gray">税额</font>', name: 'taxrateMoney', width: 120},
                      { display: '<font color="gray">不含税单价</font>', name: 'price', width: 120},
                      { display: '折扣(%)<font color="red">*</font>', name: 'discount', width: 120},
                      { display: '<font color="gray">不含税折扣额</font>', name: 'discountMoney', width: 120},
                      { display: '<font color="gray">含税折扣额</font>', name: 'hsdiscountMoney', width: 120},
                      { display: '<font color="gray">不含税总金额</font>', name: 'summoney', width: 120},
                      { display: '<font color="gray">含税总金额</font>', name: 'sumPMoney', width: 120},
                      { display: '<font color="gray">基本单位已入库数量</font>', name: 'inCount', width: 120},
                      { display: '<font color="gray">基本单位已退货数量</font>', name: 'returnJquantity', width: 120},
                      { display: '<font color="gray">单位换算率</font>', name: 'unitconvert', width:100 }];
    var column3 = column1;                 
    if('${po.billstatus}' != "" && '${po.billstatus}' != "0"){
    	column3 = column2;    
    }	
	var griddata ={};
	grid = $("#table1").ligerGrid({
				  columns: column3,
                  enabledEdit: true,
                  usePager: true,pageSize:1000,pageSizeOptions:[1000],
                  //data : griddata,
                  parms:[{ name : 'id' , value : '${po.id}'}],
                  url : basic_Url+"/griditems.do",
                  width: "100%", height:'90%', checkbox: true,
                  toolbar: { items: [
                                     { text: '添加物料', click: ItemWindow, icon: 'add' },
                                     { line: true },
                                     { text: '删除', click: deleteRow, img: '${ctx}/js/ligerUI/skins/icons/delete.gif' }
                                     ]
                                     }
                  });
	$("#pageloading").hide();

	$("#inputForm").validate({			   
	onsubmit: true,
	 /*执行ajaxsubmit  */ 
    submitHandler: function(editform) {
        try{			    		
            url =  basic_Url+"/save.do";
            var api = frameElement.api;
        	var W = api.opener;
        	getReturnMessage(basic_Url+"/save.do","inputForm",W.searchAP);
            //CloseDialog();
        }catch(e){alert(e)}
    }
	});

// 	if('${po.billstatus}' == ""){
// 		$("#export").hide();
// 		//$("#sub").attr("disabled","disabled");//禁用保存按钮
// 		$("#sub").hide();
// 	}
// 	else if('${po.billstatus}' == "0"){
// 		//$("#save").attr("disabled","disabled");//禁用保存按钮
// 		$("#save").hide();
// 	}else{
// 		$("#sub").hide();
// 		$("#save").hide();
// 	}
	if('${po.billstatus}' != "" && '${po.billstatus}' != "0"){
		$("input").attr("readonly","readonly");
		$("input").attr("onclick","");
		$("select").attr("disabled","disabled");
	}

	if('${po.billstatus}' == ""){
		$("#save1").hide();//禁用保存按钮
		$("#savej2").hide();
		$("#save2").hide();//禁用保存按钮
		$("#save3").hide();//禁用保存按钮
		$("#bohui").hide();
		$("#wanjie").hide();
		$("#poExportExcel").hide();
		
	}
	else if('${po.billstatus}' == "0" ){
		if('${user.name}' != '${po.dcruser}'){
			$("#save1").hide();
		}
		$("#save").hide();//禁用保存按钮
		$("#savej2").hide();
		$("#save2").hide();//禁用保存按钮
		$("#save3").hide();//禁用保存按钮
		$("#bohui").hide();
		$("#wanjie").hide();
		$("#poExportExcel").hide();
	}
	else if('${po.billstatus}' == "1" ){
		$("#save1").hide();//禁用保存按钮
		$("#save").hide();//禁用保存按钮
		$("#save3").hide();//禁用保存按钮
		$("#wanjie").hide();
		$("#poExportExcel").hide();
	}
	else if('${po.billstatus}' == "2"){
		$("#save1").hide();//禁用保存按钮
		$("#savej2").hide();
		$("#save2").hide();//禁用保存按钮
		$("#save").hide();//禁用保存按钮
		$("#wanjie").hide();
		$("#poExportExcel").hide();
	}else if ('${po.billstatus}' == "3"){
		if('${user.name}'!='admin'){
			if('${user.name}' != '${po.dcruser}'){
				$("#wanjie").hide();
			}
		}
		$("#save").hide();//禁用保存按钮
		$("#save1").hide();//禁用保存按钮
		$("#savej2").hide();
		$("#save2").hide();//禁用保存按钮
		$("#save3").hide();//禁用保存按钮
		$("#bohui").hide();
	}else if('${po.billstatus}' == "4"){
		if('${user.name}'!='admin'){
			if('${user.name}' != '${po.dcruser}'){
				$("#wanjie").hide();
			}
		}
		$("#save").hide();//禁用保存按钮
		$("#save1").hide();//禁用保存按钮
		$("#savej2").hide();
		$("#save2").hide();//禁用保存按钮
		$("#save3").hide();//禁用保存按钮
		$("#bohui").hide();
	}
	else{
		$("#save").hide();//禁用保存按钮
		$("#save1").hide();//禁用保存按钮
		$("#savej2").hide();
		$("#save2").hide();//禁用保存按钮
		$("#save3").hide();//禁用保存按钮
		$("#bohui").hide();
		$("#wanjie").hide();
	}
	if('${flag}' == 'EDIT'){
		$("#pocode").attr("readonly","readonly");
	}
	/* <c:forEach items='${itemlistDos}' var='item'>
    	var manager = $("#table1").ligerGetGridManager();
    	manager.addRow2({
    		id : "${item.id}",
    		materialsid : "${item.materialsid}",
    		code : "${item.code}",
			name : "${item.name}",
			itmetype : "${item.itmetype}",
			spec : "${item.spec}",
			unit : "${item.unit}",
			junit : "${item.junit}",
			quantity : "${item.quantity}",
			jquantity : "${item.jquantity}",
			inCount : "${item.inCount}",
			returnJquantity : "${item.returnJquantity}",
			price : "${item.price}",
			stockPrice : "${item.stockPrice}",
			taxRate : "${item.taxRate}",
			taxrateMoney : "${item.taxrateMoney}",
			discount : "${item.discount}",
			discountMoney : "${item.discountMoney}",
			hsdiscountMoney : "${item.hsdiscountMoney}",
			summoney : "${item.summoney}",
			sumPMoney : "${item.sumPMoney}",
			unitconvert : "${item.unitconvert}",
			openBatch : "${item.openBatch}"
		});
		</c:forEach> */
	})

	function ItemWindow() {
	if('${po.billstatus}' != "" && '${po.billstatus}' != "0"){
		return false;
	}else if($("#spcode").val() == null || $("#spcode").val()==""){
		$.dialog.alert("您还没有选择供应商,请先选择供应商!");
		return false;
	}else if($("#currency").val() == null || $("#currency").val()==""){
		$.dialog.alert("您还没有选择币种,请先选择币种!");
		return false;
	}else{
		getDG().dialog(
				{
					title : '选择材料',
					width : 650,
					height : 350,
					content : 'url:' + sys_context+ '/public/windowalert/itemmanager.do',//
					lock : true,
					max : true,
					min : true,
					ok : function() {
						var getSelectedHub = this.content.getSelected();
						var manager = $("#table1").ligerGetGridManager();
						if (getSelectedHub != null) {
							 $(getSelectedHub).each(function ()
							            {
								 var taxPrice;
								 var taxRate;
								 $.ajax({
								      url:"${ctx}/yd/logic/poquote/newPrice.do",
								      global: false,
								      type: "POST",
								      async:false,
								      dataType: "json",
								      data: ({
								    	  materialsid:this.id,
								    	  gyscode:$("#spcode").val(),
								      }),		     
								      success: function(msg){
								    	 result = msg;
								    	 var quote = eval("("+JSON.stringify(result)+")"); 
								    	 if(quote != null && quote != ""){
 								    		 //var quote = eval("("+JSON.stringify(result)+")"); 
								    		 taxPrice = quote.taxPrice;
									    	 taxRate=quote.taxRate;
								    	 }else{
								    		 taxPrice =0.0;
								    		 taxRate=0;
								    	 }
								      }
							   });
								 		var data = grid.getData();
								 		if(data != null && data.length>0){
								 			for(var i =0;i<data.length;i++){
								 				if(data[i].code == this.code){
								 					manager.deleteRow(i);
								 				}
								 			}	
								 		}
									                manager.addRow2({
									                materialsid: this.id,
									                code: this.code,
								                	name: this.name,
								                	itmetype: this.itmetype,
								                	junit: this.unit,
								             		rmb : taxPrice.toFixed(4),
								                	taxRate : taxRate,
								                	discount : '100',
								                	spec : this.spec,
								                	openBatch :this.remark2
								                });
							 });
							this.content.Close();
						}
						return false;
					},
					cancelVal : '关闭',
					cancel : true
				}).zindex();
		}
	}

	function exportAP(){
		var id=$("#id").val();
		if(id!=""){
			var path = basic_Url+"/exportExcel.do?id="+id;
	   		window.open(path,"_blank");
		}
		else{
			$.dialog.alert("请先保存再导出");
		}
	}

	function deleteRow()
	{ 
		if('${po.billstatus}' != "" && '${po.billstatus}' != "0"){
			return false;
		}else{
		grid.deleteSelectedRow();
		}
	}
	
	function submitForm(param) {
		//设置ajax全局同步

		//var data = JSON.stringify(grid.getData());
		var data = grid.getData();
		var dl = grid.getDeleted();
		if (data.length == 0) {
			$.dialog.alert("请选择申请物料");
			return false;
		}
		var ba = true;
		if (data != null) {
			var i = 0;
			$(data).each(function() {
				i++;
				if (this.unit=="" ||this.unit==undefined ||this.unit==null) {
					$.dialog.alert("您第" + i + "行单位没有填写");
					ba = false;
					return false;
				}
				if (isNaN(this.quantity) ||this.quantity==undefined ||this.quantity==null) {
					$.dialog.alert("您第" + i + "行数量没有填写");
					ba = false;
					return false;
				}
				if (parseInt(this.quantity)<=0) {
					$.dialog.alert("您第" + i + "行数量不能小于或为0");
					ba = false;
					return false;
				}
				if (isNaN(this.stockPrice) ||this.stockPrice==undefined ||this.stockPrice==null) {
					$.dialog.alert("您第" + i + "行的含税单价没有填写");
					ba = false;
					return false;
				}
				if (this.stockPrice<=0) {
					$.dialog.alert("您第" + i + "行的含税单价不能小于或为0");
					ba = false;
					return false;
				}
				if (isNaN(this.taxRate) ||this.taxRate==undefined ||this.taxRate==null) {
					ba = false;
					$.dialog.alert("您第" + i + "行的税率没有填写");
					return false;
				}
				if (isNaN(this.discount) ||this.discount==undefined ||this.discount==null) {
					ba = false;
					$.dialog.alert("您第" + i + "行的折扣没有填写");
					return false;
				}
				
 				if (parseFloat(this.taxRate)<0) {
 					ba = false;
 					$.dialog.alert("您第" + i + "行的税率不能小于0");
 					return false;
 				}
 				if (parseFloat(this.discount)<=0) {
 					ba = false;
 					$.dialog.alert("您第" + i + "行的折扣必须大于0");
 					return false;
 				}
 				if (parseFloat(this.discount)>100) {
 					ba = false;
 					$.dialog.alert("您第" + i + "行的折扣不能大于100");
 					return false;
 				}
				if (parseFloat(this.hsdiscountMoney)<=0) {
					$.dialog.alert("您第" + i + "行的含税折扣额必须大于0");
					ba = false;
					return false;
				}
			});
		}
		jQuery.ajaxSettings.async = false;
		var str="";
		if(param==3){
			str="是否审核完结请选择(Yes或者No)!";
		}else if(param==5){
			str="是否完结订单请选择(Yes或者No)!";
		}
		if(param==3 || param==5){
			getDG().dialog({content: str,width: 250,lock: true,max: false,min: false,
				title:'Confirm Infor',
				button: [
				         {
				             name: 'Yes',
				             callback: function(){
				        		   if (ba) {
				        				$("#type").val(param);
				        				$("#itemdata").val(JSON.stringify(data));
				        				$("#itemdelete").val(JSON.stringify(dl));
				        				$("#inputForm").submit();
				        			}
					            }
				         },
				         {
				        	   name: 'No',
				        	   focus: true
				         }             
				     ]
			}).zindex();
			}else{
				if (ba) {
					$("#type").val(param);
					$("#itemdata").val(JSON.stringify(data));
					$("#itemdelete").val(JSON.stringify(dl));
					$("#inputForm").submit();
				}
			}
		
	}
	
// 	function getUnitconvert(e){
//      	var rowData=grid.getRow($(e).parent()[0]);
// 		 $.ajax({
// 		      url: basic_Url+"/polist.do",
// 		      global: false,
// 		      type: "POST",
// 		      async:false,
// 		      dataType: "json",
// 		      data: ({
// 		    	   id:rowData.id,
// 		    	   code:rowData.code,
// 		    	   unit:rowData.unit,
// 		      }),		     
// 		      success: function(msg){
// 		    	 result = msg;
// 		    	 var bmu = eval("("+JSON.stringify(result)+")"); 
// 		    	 $("#unitconvert").val(bmu[0].unitconvert);
// 		      }
// 	   });
//     }
	
// 	function bhcheck(){
// 		if($("#id").val()==""){
// 			$.dialog.alert("没有提交无法驳回");
// 			return false;
// 		}
// 		window.location="${ctx}/yd/logic/po/updateState.do";
// 		$.ajax({
// 	      	url: "${ctx}/yd/logic/po/updateState.do",
// 	      	global: false,
// 	      	type: "POST",
// 	     	dataType: "json",
// 	      	data: ({
// 	    	  	rows : $("#id").val()
// 	      	}),		     
// 	      	success: function(msg){
// 	    	  	if(msg.msg=="SUCCESS"){
// 	    		  	$.dialog.alert("驳回成功");
// 	    	  	}
// 	    	  	if(msg.msg=="ERROR"){
// 	    		  	$.dialog.alert("驳回失败");
// 	    	  	}
// 	    	  	CloseDialog();
// 	    	  	var api = frameElement.api;
// 	         	var W = api.opener;
// 	            W.searchAP();
// 	   		}
// 		});
// 	}
function exportAP() {
		var path = basic_Url + "/exportExcel.do?id=${po.id}";
		window.open(path, "_blank");
	}
</script>

</head>

<body>

<form id="inputForm" action="" method="post">
<input type="hidden" id="id" name="id" value="${po.id}"/>
<input type="hidden" id="version" name="version" value="${po.version}"/>
<input type="hidden" id="itemdata" name="itemdata" value=""/>
<input type="hidden" id="itemdelete" name="itemdelete" value=""/>
<input type="hidden" id="dataItem" name="dataItem"/>
<input type="hidden" id="unitconvert" name="unitconvert"/>
<input type="hidden" id="type" name="type" value=""/>
<!-- 用于标识提交按钮 -->
<input type="hidden" id="submitFlag" value="" />
 <div class="pageContent" >
    <div class="panel" >
         <table class="TableBlock" align="center">
   		           <tr>
   		           <c:if test="${not empty po.pocode}">
                    <td>采购编号:</td>
   		                 <td>
   		               	 	<input type="text"  id="pocode" name="pocode"  class="required inp_width_98p" value="${po.pocode}" />
   		             </td>
   		            </c:if> 
   		            <td>供应商编号:</td>
					<td>
					<c:choose>
						<c:when test="${empty po.spcode}">
							<select id="spcode" name="spcode"  class="required inp_width_98p" >
							<option id="" value=''></option>
   		                 	<c:forEach items='${company}' var='state'>
   		                 	<option value='${state.code}'>${state.code}-${state.name}</option>
   		                 	</c:forEach>
   		                 	</select>
						</c:when>
						<c:otherwise>
							<input type="text" id="spcode" name="spcode" value="${po.spcode}" class="inp_width_98p" readonly="readonly"  />
						</c:otherwise>
					</c:choose>
   		            </td>
   		            <c:if test="${empty po.pocode}">
                    <td colspan="2"></td>
   		            </c:if>    
   		           </tr>
				<tr>
   		                <td>供应商名称:</td>
   		           		<td><input type="text"  id="spname" name="spname" class="inp_width_98p"  value="${po.spname}"  readonly="readonly"/></td>
						<td>邮箱:</td>
   		           		<td><input type="text"  id="spemail" name="spemail" class="inp_width_98p"  value="${po.spemail}"  readonly="readonly"/></td>
					</tr>
					
					
					<tr>
					 	 <td>联系人:</td>
   		           		 <td><input type="text"  id="spattachperson" name="spattachperson" class="inp_width_98p"  value="${po.spattachperson}"  readonly="readonly"/></td>    
   		                 <td>手机:</td>
   		           		 <td><input type="text"  id="spmobil" name="spmobil" class="inp_width_98p"  value="${po.spmobil}"  readonly="readonly"/></td>
					</tr>
					
					<tr>
					 	 <td>电话:</td>
   		           		 <td><input type="text"  id="sptelephone" name="sptelephone"  class="inp_width_98p" value="${po.sptelephone}"  readonly="readonly"/></td>    
   		                 <td>传真:</td>
   		           		 <td><input type="text"  id="spfax" name="spfax" class="inp_width_98p"  value="${po.spfax}"  readonly="readonly"/></td>
					</tr>
				
					<tr>
					 	 <td>地址:</td>
   		           		 <td colspan="3"><input type="text"  id="spaddress" name="spaddress" class="inp_width_98p"  value="${po.spaddress}"  readonly="readonly"/></td>    
					</tr>
					
   		           <tr>
   		                 	<td>采购方式:</td>
		   		           <td>
		   		           	<select id="popattern" class="required inp_width_98p" name="popattern" >
		   		           		<option></option>
		   		           		<option>赊购</option>
		   		           		<option>现购</option>
		   		           	</select>
		   		           	<script type="text/javascript">
		   		           		$("#popattern").val('${po.popattern}');
		   		           	</script>
		   		           </td>
		   		           
		   		            <td>摘要:</td>
   		           			<td><input type="text"  id="tabloid" name="tabloid"  class="inp_width_98p" value="${po.tabloid}" /></td>
   		           </tr>
   		           <tr>
   		           <td>订购日期:</td>
   		           	  	<td>
   		                 	<input type="text" id="dgrq" class="required inp_width_98p" readonly="readonly" name="dgrq" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"
							value="<fmt:formatDate value="${po.dgrq}" pattern="yyyy-MM-dd" type="both" />" />
   		                 	</td>
   		           	<td>收货日期:</td>
   		           	  	<td>
   		                 	<input type="text" id="shrq" class="required inp_width_98p" readonly="readonly" name="shrq" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"
							value="<fmt:formatDate value="${po.shrq}" pattern="yyyy-MM-dd" type="both" />" />
   		                 	</td>
   		           </tr>
   		           
   		           <tr>
   		           <td>币种:</td>
   		           <td>
   		           	<select id="currency" class="required inp_width_98p" name="currency" >
   		           		<option></option>
   		           	<c:forEach items="${currency }" var="currency">
   		           		<option value="${currency.currencyname }">${currency.currencyname }</option>
   		           	</c:forEach>	
   		           	</select>
   		           	<script type="text/javascript">
   		           		$("#currency").val('${po.currency}');
   		           	</script>
   		           </td>
   		           	<td>汇率:</td>
   		           	<td><input type="text"  id="exchangeRate" name="exchangeRate" class="required inp_width_98p" value="${po.exchangeRate}" readonly="readonly"/></td>
   		           </tr>
   		           
   		           <tr>
   		           <td>支付方式:</td>
   		           <td>
   		           	<select id="fkpattern" class="required inp_width_98p" name="fkpattern" >
   		           		<option></option>
   		           		<c:forEach items="${paymentDOs }" var="paymentDOs">
   		           			<option value="${paymentDOs.name }">${paymentDOs.name }</option>
   		           		</c:forEach>
   		           	</select>
   		           	<script type="text/javascript">
   		           		$("#fkpattern").val('${po.fkpattern}');
   		           	</script>
   		           </td>
   		           	<td>结算日期:</td>
   		           	<td><input type="text"  id="fkdate" name="fkdate" class="required inp_width_98p" 
   		           	 readonly="readonly" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"
							value="<fmt:formatDate value="${po.fkdate}" pattern="yyyy-MM-dd" type="both" />"
   		           	 /></td>
   		           </tr>
   		           
   		            <tr>
   		            <td>部门:</td>
   		            <td>
   		            	<select id="depacode" name="depacode"  class="inp_width_98p">
   		            		<option></option>
   		            		<c:forEach items="${departmentDOs }" var="dept">
   		            			<option value="${dept.depcode }">${dept.depname }</option>
   		            		</c:forEach>
   		            	</select>
   		            	<input type="hidden" name="depname" id="depname" value="${po.depname}"/>
   		            	<script type="text/javascript">
   		            		$("#depacode").val('${po.depacode}');
   		            		
   		            		$("#depacode").change(function(){ 
	   		           		  $("#depname").val($("#depacode").find("option:selected").text());
   		           			}); 
   		            	</script>
   		            </td>
   		           
   		            <td>备注:</td>
   		           	<td><input  id="remark" name="remark" value="${po.remark}"  class="inp_width_98p"/></td>
   		          </tr>
                </table>
                <div id="table1"> </div>               
         </div>
		<div class="formBar">
	        <ul>
		       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save" onclick="submitForm(0)">保存</button></div></div></li>
		       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save1" onclick="submitForm(1)">提交</button></div></div></li>
		        <li><div class="button"><div class="buttonContent"><button type="button" id="poExportExcel" class="export" onclick="exportAP()">导出</button></div></div> </li>
		        <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="wanjie" onclick="submitForm(5)">完结订单</button></div></div></li>
		       <webres:displaycontroller elementId="CGDD_BH_CHEECK_PH" description="采购订单申请驳回">
		       		<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="bohui" onclick="submitForm('bh')">驳回</button></div></div></li>
		      	</webres:displaycontroller>
		       <webres:displaycontroller elementId="CGDD_YJ_CHEECK" description="采购订单二级审核">
		       			<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save2" onclick="submitForm(2)">二级审核</button></div></div></li>
		       			<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="savej2" onclick="submitForm(3)">二级审核完结</button></div></div></li>
		      		</webres:displaycontroller>
		      		<webres:displaycontroller elementId="CGDD_EJ_CHEECK" description="采购订单三级审核">
		       			<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save3" onclick="submitForm(3)">三级审核</button></div></div></li>
		      		</webres:displaycontroller>
		       <li><div class="button"><div class="buttonContent"><button type="button" class="print" onclick="CloseDialog()">关闭</button></div></div></li>
	        </ul>
        </div>
    </div>
</form>
</body>
</html>
